#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/9/24
# @Author  : YunZhen
# @File    : venv_check.py
# @Software: PyCharm
"""
环境配置验证脚本
"""
import sys
import subprocess
import uiautomator2.version as u2_version


def check_environment():
    print("=== 环境配置验证: 请确保已安装ADB并配置环境变量，且设备已通过USB连接并开启USB调试模式 === \n")
    # 检查Python
    try:
        print(f'Python环境路径: {sys.prefix}')
        print(f"Python版本: {sys.version}\n")
    except Exception as e:
        print(f"Python检查失败: {e}")
        return False

    # 检查uiautomator2
    try:
        print(f"uiautomator2版本: {u2_version.__version__}")
    except Exception as e:
        print(f"uiautomator2检查失败: {e}，检查是否正确安装")
        return False

    # 检查ADB
    try:
        result = subprocess.run(['adb', 'version'],
                                capture_output=True, text=True)
        print(f"ADB信息: {result.stdout.splitlines()[0] if result.stdout else '未找到'}\n")
    except Exception as e:
        print(f"ADB检查失败: {e}")
        return False

    # 检查设备连接
    try:
        devices = subprocess.run(['adb', 'devices'],
                                 capture_output=True, text=True)
        print("连接的设备:")
        print(devices.stdout)
    except Exception as e:
        print(f"设备检查失败: {e}")
        return False

    print("环境验证完成！")
    return True


if __name__ == "__main__":
    check_environment()
